package cn.com.jrr.core.service;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.com.jrr.core.common.ToolUtils;
import cn.com.jrr.core.dao.impl.BaseDaoImpl;
import cn.com.jrr.core.model.DataTableRequest;
import cn.com.jrr.core.model.DataTableResponse;
import cn.com.jrr.core.model.PageModel;
import cn.com.jrr.core.model.Vote;

@Service
public class VoteService{
	@Resource
	private BaseDaoImpl<Vote> baseDaoImpl;
	@Autowired
	PageModel<Vote> pageModel;

	/**
	 * 查询数据
	 * */
	public DataTableResponse<Vote> getAll(DataTableRequest dataTableRequest){
		pageModel.setCurrentItem(dataTableRequest.getCurrentItem());
		pageModel.setPageSize(dataTableRequest.getPageSize());
		String sql="select * from vote order by id desc";
		Object [] obj=new String[]{"id","title","entryid","updateid","code","url","startdt","enddt"};
		sql=ToolUtils.SearchAndSortHql(sql, dataTableRequest, obj);
		DataTableResponse<Vote> dataTableResponse=baseDaoImpl.findBySql(sql,pageModel,Vote.class);
		return  dataTableResponse;
	}
	/**
	 * 添加数据
	 * */
	public void add(Vote vote){
		baseDaoImpl.saveO(vote);
	}
	/**
	 * 获取一条数据
	 * */
	public Vote get(Integer id){
		return  baseDaoImpl.get(Vote.class, id);
	}
	/**
	 * 修改数据
	 * */
	public void update(Vote vote){
		baseDaoImpl.updateObj(vote);
	}
	/**
	 * 删除数据
	 * */
	public int delete(Integer id){
		return  baseDaoImpl.updateBySql("delete from vote where id=?", new Object[]{id});
	}
	/**
	 * 设置访问地址url
	 * */
	public int setUrl(String url,Integer id){
		return  baseDaoImpl.updateBySql("update vote set url=? where id=?", new Object[]{url,id});
	}



}
